<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/12
 * Time: 9:48
 */

namespace app\common\model;
use think\Db;


class Integral extends \think\Model
{
    private static $instance;
    public static $integral_status = array(
        '1'   =>   '注册',
        '2'   =>   '实名认证成功',
        '3'   =>   '发布内容',
        '4'   =>   '留言',
        '5'   =>   '领养成功'
    );
    /**
     * 用户积分信息列表
     * @return   $list   用户积分列表
     */
    public function userIntegral($search, $pageSize, $user_id){
        $model = self::instance();
        $where = $this->getWhere($search);
        $where['integral_user_id'] = array('=', $user_id);
        $list = $model
            ->where($where)
            ->field('integral_time, integral_num, integral_status')
            ->paginate($pageSize);
        return $list;
    }
    /**
     * 查询条件
     * @return   $where   查询条件
     */
    public function getWhere($search){
        $where = '';
        if($search[0] != ''){
            $where['integral_status'] = array('=', $search[0]);
        }
        if($search[1] > 0 && $search[2] > 0){
            $where['integral_time'] = array('between', array($search[1], $search[2]));
        }else if($search[1] > 0){
            $where['integral_time'] = array('egt', $search[1]);
        }else if($search[2] > 0){
            $where['integral_time'] = array('elt', $search[2]);
        }else{
            $where['integral_time'] = array('egt', 0);
        }
        return $where;
    }

    public static function instance()
    {
        if (!(self::$instance instanceof self)) {
            self::$instance = new self();
        }
        return self::$instance;
    }
}